﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 人事工资管理系统
{
    public partial class frmJFmanage : Form
    {
        public frmJFmanage()
        {
            InitializeComponent();
        }
        PMSClass.DBOperate operate = new PMSClass.DBOperate();
        SqlConnection conn = PMSClass.DBConnection.MyConnection();
        private void frmJFmanage_Load(object sender, EventArgs e)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from tb_employee", conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                cbbUserNum.Items.Add(sdr["employeeID"].ToString());
            }
            sdr.Close();
            conn.Close();
        }

        private void cbbUserNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = "select * from tb_employee where employeeID='" + cbbUserNum.Text + "'";
            DataSet ds = operate.GetTable(str);
            ds.Dispose();
            txtname.Text = ds.Tables[0].Rows[0][2].ToString();
            txtdep.Text = ds.Tables[0].Rows[0][4].ToString();
        }

        private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (cbbUserNum.Text == "" || cbbUserJFType.Text == "" || txtJFcontent.Text == "" || txtJFdate.Text == "" || txtCXDate.Text == "")
            {
                MessageBox.Show("请将信息填写完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                if (cbbUserJFType.Text == "奖励")
                {
                    if (txtJL.Text == "")
                    {
                        MessageBox.Show("请输入奖励金额！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    {
                        string sql = "select count(*)from tb_prize where UserID='" + cbbUserNum.Text + "'";
                        int i = operate.HumanNum(sql);
                        if (i > 0)
                        {
                            MessageBox.Show("员工编号已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else
                        {
                            string str = "insert into tb_prize(UserID,UserName,UserDep,UserJF,UserJFcontent,UserJLMoney,UserFKMoney,UserJFDate,UserCXDate)values('" + cbbUserNum.Text + "','" + txtname.Text + "','" + txtdep.Text + "','" + cbbUserJFType.Text + "','" + txtJFcontent.Text + "','" + txtJL.Text + "','" + txtFK.Text + "','" + txtJFdate.Text + "','" + txtCXDate.Text + "')";
                            operate.OperateData(str);
                            MessageBox.Show("添加成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    try
                    {
                        if (txtFK.Text == "")
                        {
                            MessageBox.Show("罚款金额不为空");
                        }
                        else
                        {
                            string sql = "select count(*) from tb_prize where UserID='" + cbbUserNum.Text + "'";
                            int i = operate.HumanNum(sql);
                            if (i > 0)
                            {
                                MessageBox.Show("员工编号已存在！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            else
                            {
                                string str = "insert into tb_prize(UserID,UserName,UserDep,UserJF,UserJFcontent,UserJLMoney,UserFKMoney,UserJFData,UserCXData) values('" + cbbUserNum.Text + "','" + txtdep.Text + "','" + cbbUserJFType.Text + "','" + txtJFcontent.Text + "','" + txtJL.Text + "','" + txtFK.Text + "','" + txtJFdate.Text + "','" + txtCXDate.Text + "')";
                                operate.OperateData(str);
                                MessageBox.Show("添加成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }

        private void cbbUserJFType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbUserJFType.Text == "奖励")
            {
                txtFK.Enabled = false;
                txtFK.Text = "0";
                txtJL.Text = "true";
            }
            else
            {
                txtJL.Enabled = false;
                txtJL.Text = "0";
                txtFK.Enabled = true;
            }
        }
    }
}
